import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { AlarmService } from './alarm.service';
import { CreateAlarmDto, BaseAlarmDto, UpdateAlarmDto, QueryAlarmDto, ListAlarmDto } from './dto/alarm.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';

@ApiTags('消息报警表，存储因对话内容触发的各类报警信息')
@Controller('system/alarm')
export class AlarmController {
  constructor(private readonly alarmService: AlarmService) {}

  @ApiOperation({ summary: '消息报警表，存储因对话内容触发的各类报警信息-创建' })
  @ApiDataResponse(BaseAlarmDto)
  // @RequirePermission('system:alarm:add')
  @Post()
  create(@Body() body: CreateAlarmDto) {
    return this.alarmService.create(body);
  }

  @ApiOperation({ summary: '消息报警表，存储因对话内容触发的各类报警信息-列表' })
  @ApiDataResponse(ListAlarmDto, true, true)
  @RequirePermission('system:alarm:list')
  @Get('list')
  findAll(@Query() query: QueryAlarmDto) {
    return this.alarmService.findAll(query);
  }

  @ApiOperation({ summary: '消息报警表，存储因对话内容触发的各类报警信息-列表' })
  @ApiDataResponse(ListAlarmDto, true, true)
  // @RequirePermission('system:alarm:list')
  @Get('messageAlarmList/:id')
  getMessageAlarmList(@Param('id') id: number, @Query() query: QueryAlarmDto) {
    return this.alarmService.getMessageAlarmList(id, query.pageNum, query.pageSize);
  }

  @ApiOperation({ summary: '消息报警表，存储因对话内容触发的各类报警信息-详情' })
  @ApiDataResponse(BaseAlarmDto)
  @RequirePermission('system:alarm:query')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.alarmService.findOne(id);
  }

  @ApiOperation({ summary: '消息报警表，存储因对话内容触发的各类报警信息-修改' })
  @ApiDataResponse()
  @RequirePermission('system:alarm:edit')
  @Put()
  update(@Body() body: UpdateAlarmDto) {
    return this.alarmService.update(body);
  }

  @ApiOperation({ summary: '消息报警表，存储因对话内容触发的各类报警信息-删除' })
  @ApiDataResponse()
  @RequirePermission('system:alarm:remove')
  @Delete(':id')
  remove(@Param('id') id: string) {
    const ids = id.split(',').map((id) => +id);
    return this.alarmService.remove(ids);
  }
}
